#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/socket.h>

int main(int argc,char *argv)
{
    int fd = -1;

    fd = socket(AF_INET,SOCK_STREAM,0);
    if(fd < 0)
    {
	printf("fd = %d\n",fd);
	exit(EXIT_FAILURE);
    }
    int flag = fcntl(fd,F_GETFL,0);
    printf("fd = %d,flag = 0x%x,pid = %d\n",fd,flag,getpid());
    int ret  = fcntl(fd,F_SETFL,flag|O_NONBLOCK);
    printf("set nonblock ret = %d\n",ret);

    while(1)
    {
	sleep(1);
    }
    close(fd);
    exit(EXIT_SUCCESS);
}
